import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "@/views/Login.vue";
import Layout from "@/layout/index.vue";
import HomeView from "@/views/HomeView.vue";

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'login',
    component: Login
  },
  {
    path: '/layout',
    name: 'layout',
    component: Layout,
    redirect: '/layout/home',
    children: [
      {
        path: 'about',
        name: 'about',

        component: () => import(/* webpackChunkName: "about" */ '../views/Test/AboutView.vue')
      },
      {
        path: 'home',
        name: 'home',
        component: HomeView
      },
    ]

  },



]
const router = new VueRouter({
  routes
})

// 防止连续点击多次路由报错
let routerPush = VueRouter.prototype.push;
let routerReplace = VueRouter.prototype.replace;
// push
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(err => err)
}
// replace
VueRouter.prototype.replace = function push(location) {
  return routerReplace.call(this, location).catch(err => err)
}

export default router